<?php
namespace app\user\loglic;

class Datas
{
    //批量写入插件初始配置
    public function insertConfig()
    {
        return \daicuo\Op::write([
            'theme'                   => 'default',
            'theme_wap'               => 'default',
            'page_size'               => 20,
            'title_login'             => '用户登录',
            'keywords_login'          => '用户登录',
            'description_login'       => '已注册帐号请直接登录',
            'title_register'          => '用户注册',
            'keywords_register'       => '加入我们,免费注册',
            'description_register'    => '未注册帐号请先注册',
            'score_register'          => 10,
            'score_invite'            => 0,
            'score_recharge'          => 0,
            'score_group_contributor' => 10,
            'score_group_vip'         => 1000,
        ],'user','config','system','0','yes');
    }
    
    //批量添加路由伪静态
    public function insertRoute()
    {
        config('common.validate_name', '');
        
        config('common.validate_scene', '');
        
        config('common.where_slug_unique', false);
        
        return \daicuo\Route::save_all([
            [
                'rule'        => 'user$',
                'address'     => 'user/index/index',
                'method'      => 'get',
                'op_module'   => 'user',
                'op_controll' => 'route',
                'op_action'   => 'config',
            ],
            [
                'rule'        => 'user/[:slug]$',
                'address'     => 'user/index/slug',
                'method'      => 'get',
                'op_module'   => 'user',
                'op_controll' => 'route',
                'op_action'   => 'config',
            ],
            [
                'rule'        => 'login$',
                'address'     => 'user/login/index',
                'method'      => '*',
                'op_module'   => 'user',
                'op_controll' => 'route',
                'op_action'   => 'config',
            ],
            [
                'rule'        => 'register$',
                'address'     => 'user/register/index',
                'method'      => '*',
                'op_module'   => 'user',
                'op_controll' => 'route',
                'op_action'   => 'config',
            ],
            [
                'rule'        => 'ucenter$',
                'address'     => 'user/center/index',
                'method'      => 'get',
                'op_module'   => 'user',
                'op_controll' => 'route',
                'op_action'   => 'config',
            ],
            [
                'rule'        => 'logout$',
                'address'     => 'user/logout/index',
                'method'      => 'get',
                'op_module'   => 'user',
                'op_controll' => 'route',
                'op_action'   => 'config',
            ],
        ]);
    }
    
    //批量添加初始用户
    public function insertUser()
    {
        config('custom_fields.user_meta', ['user_pid', 'user_score', 'user_capabilities']);
        
        config('common.validate_name', '');
        
        config('common.validate_scene', '');
        
        config('common.where_slug_unique', '');

        return \daicuo\User::save_all([
            [
                'user_name'         => 'user1',
                'user_nice_name'    => 'user1',
                'user_pass'         => 'user1',
                'user_email'        => 'user1@daicuo.org',
                'user_mobile'       => '13800138001',
                'user_status'       => 'normal',
                'user_module'       => 'user',
                'user_capabilities' => 'subscriber',
                'user_slug'         => 'userone',
                'user_score'        => 0,
                'user_pid'          => 0,
            ],
            [
                'user_name'         => 'user2',
                'user_nice_name'    => 'user2',
                'user_pass'         => 'user2',
                'user_email'        => 'user2@daicuo.org',
                'user_mobile'       => '13800138002',
                'user_status'       => 'normal',
                'user_module'       => 'user',
                'user_capabilities' => 'subscriber',
                'user_slug'         => 'usertwo',
                'user_score'        => 0,
                'user_pid'          => 0,
            ],
        ]);
    }
    
    //批量添加权限
    public function insertAuth()
    {
        config('common.validate_name', '');
        
        config('common.validate_scene', '');
        
        config('common.where_slug_unique', false);
        
        //权限节点
        $caps = [
            'api/token/refresh',
            'api/token/delete',
            'api/upload/save',
            'api/upload/delete',
            'admin/index/index',
            'admin/op/index',
            'admin/cache/index',
            'admin/video/index',
            'admin/upload/index',
            'admin/store/index',
            'admin/apply/index',
            'admin/apply/create',
            'admin/tool/index',
            'admin/route/index',
            'admin/route/create',
            'admin/route/edit',
            'admin/user/index',
            'admin/user/create',
            'admin/user/edit',
            'admin/auth/index',
            'admin/auth/create',
            'admin/auth/edit',
            'admin/category/index',
            'admin/category/create',
            'admin/category/edit',
            'admin/tag/index',
            'admin/tag/create',
            'admin/tag/edit',
            'admin/addon/index?action=index',
            'admin/addon/index?action=create',
            'admin/addon/index?action=edit',
        ];
        
        //默认数据
        $default = [
            'op_name'       => 'editor',
            'op_module'     => 'user',
            'op_controll'   => 'auth',
            'op_action'     => 'system',
            'op_order'      => 0,
            'op_status'     => 'normal',
        ];
        
        //批量添加数据
        $dataList = [];
        foreach($caps as $key=>$value){
            array_push($dataList, DcArrayArgs(['op_value'=>$value],$default));
        }
        return \daicuo\Op::save_all($dataList);
    }
    
    //批量添加分类/标签/导航
    public function insertTerm()
    {
        config('custom_fields.term_meta', ['navs_url','navs_active','navs_target']);
        
        config('common.validate_name', '');
        
        config('common.validate_scene', '');
        
        config('common.where_slug_unique', false);
        
        return \daicuo\Term::save_all([
            [
                'term_order'      => 0,
                'term_parent'     => 0,
                'term_type'       => 'navs',
                'term_tpl'        => 'index',
                'term_name'       => '登录',
                'term_slug'       => 'login',
                'term_info'       => '已注册帐号请登录',
                'term_action'     => 'navbar',
                'term_controll'   => 'login',
                'term_module'     => 'user',
                'term_status'     => 'public',
                'navs_url'        => 'user/login/index',
                'navs_active'     => 'userloginindex',
                'navs_target'     => '_self',
            ],
            [
                'term_order'      => 0,
                'term_parent'     => 0,
                'term_type'       => 'navs',
                'term_tpl'        => 'index',
                'term_name'       => '注册',
                'term_slug'       => 'register',
                'term_info'       => '免费注册帐号',
                'term_action'     => 'navbar',
                'term_controll'   => 'register',
                'term_module'     => 'user',
                'term_status'     => 'public',
                'navs_url'        => 'user/register/index',
                'navs_active'     => 'userregisterindex',
                'navs_target'     => '_self',
            ],
            [
                'term_order'      => 0,
                'term_parent'     => 0,
                'term_type'       => 'navs',
                'term_tpl'        => 'index',
                'term_name'       => '用户中心',
                'term_slug'       => 'center',
                'term_info'       => '用户中心首页',
                'term_action'     => 'navbar',
                'term_controll'   => 'center',
                'term_module'     => 'user',
                'term_status'     => 'private',
                'navs_url'        => 'user/center/index',
                'navs_active'     => 'usercenterindex',
                'navs_target'     => '_self',
            ],
            [
                'term_order'      => 0,
                'term_parent'     => 0,
                'term_type'       => 'navs',
                'term_tpl'        => 'index',
                'term_name'       => '安全退出',
                'term_slug'       => 'logout',
                'term_info'       => '安全退出已登录帐号',
                'term_action'     => 'navbar',
                'term_controll'   => 'logout',
                'term_module'     => 'user',
                'term_status'     => 'private',
                'navs_url'        => 'user/logout/index',
                'navs_active'     => 'userlogoutindex',
                'navs_target'     => '_self',
            ],
            //侧边栏
            [
                'term_order'      => 99,
                'term_parent'     => 0,
                'term_type'       => 'navs',
                'term_tpl'        => 'index',
                'term_name'       => '用户中心',
                'term_slug'       => 'center',
                'term_info'       => '用户中心首页',
                'term_action'     => 'sitebar',
                'term_controll'   => 'center',
                'term_module'     => 'user',
                'term_status'     => 'private',
                'navs_url'        => 'user/center/index',
                'navs_active'     => 'usercenterindex',
                'navs_target'     => '_self',
            ],
            [
                'term_order'      => 0,
                'term_parent'     => 0,
                'term_type'       => 'navs',
                'term_tpl'        => 'index',
                'term_name'       => '积分充值',
                'term_slug'       => 'center',
                'term_info'       => '充值网站积分',
                'term_action'     => 'sitebar',
                'term_controll'   => 'recharge',
                'term_module'     => 'user',
                'term_status'     => 'private',
                'navs_url'        => 'user/recharge/index',
                'navs_active'     => 'usergrechargeindex',
                'navs_target'     => '_self',
            ],
            [
                'term_order'      => 0,
                'term_parent'     => 0,
                'term_type'       => 'navs',
                'term_tpl'        => 'index',
                'term_name'       => '升级VIP',
                'term_slug'       => 'center',
                'term_info'       => '升级到VIP用户组',
                'term_action'     => 'sitebar',
                'term_controll'   => 'group',
                'term_module'     => 'user',
                'term_status'     => 'private',
                'navs_url'        => 'user/group/index',
                'navs_active'     => 'usergroupindex',
                'navs_target'     => '_self',
            ],
            [
                'term_order'      => 0,
                'term_parent'     => 0,
                'term_type'       => 'navs',
                'term_tpl'        => 'index',
                'term_name'       => '修改密码',
                'term_slug'       => 'center',
                'term_info'       => '修改用户密码',
                'term_action'     => 'sitebar',
                'term_controll'   => 'repwd',
                'term_module'     => 'user',
                'term_status'     => 'private',
                'navs_url'        => 'user/repwd/index',
                'navs_active'     => 'userrepwdindex',
                'navs_target'     => '_self',
            ],
            [
                'term_order'      => 0,
                'term_parent'     => 0,
                'term_type'       => 'navs',
                'term_tpl'        => 'index',
                'term_name'       => '安全退出',
                'term_slug'       => 'logout',
                'term_info'       => '安全退出已登录帐号',
                'term_action'     => 'sitebar',
                'term_controll'   => 'index',
                'term_module'     => 'user',
                'term_status'     => 'private',
                'navs_url'        => 'user/logout/index',
                'navs_active'     => 'userlogoutindex',
                'navs_target'     => '_self',
            ],
        ]);
    }
    
}